//
//  AppDelegate.m
//  BeautifulHome
//
//  Created by dlios on 15-5-13.
//  Copyright (c) 2015年 ACE. All rights reserved.
//

#import "AppDelegate.h"
#import "XTStrategyViewController.h"
#import "XTMatchViewController.h"
#import "XTCaseViewController.h"
#import "XTGeomancyViewController.h"
#import "XTDairyViewController.h"
#import "XTMyLoginViewController.h"

@interface AppDelegate ()<UITabBarControllerDelegate>
@end

@implementation AppDelegate

- (void)dealloc
{
    
    [_window release];
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    // 创建视图控制器
    XTStrategyViewController *sVC = [[[XTStrategyViewController alloc] init] autorelease];
    XTMatchViewController *mVC = [[[XTMatchViewController alloc] init]autorelease];
    XTCaseViewController *cVC = [[[XTCaseViewController alloc] init] autorelease];
    XTGeomancyViewController *gVC = [[[XTGeomancyViewController alloc] init] autorelease];
    XTDairyViewController *dVC = [[[XTDairyViewController alloc] init] autorelease];
    XTMyLoginViewController *lVC = [[[XTMyLoginViewController alloc] init] autorelease];
    
    // 创建导航
    UINavigationController *navi1 = [[[UINavigationController alloc] initWithRootViewController:sVC] autorelease];
    [navi1.navigationBar setBackgroundImage:[UIImage imageNamed:@"999"] forBarMetrics:UIBarMetricsDefault];
    UINavigationController *navi2 = [[[UINavigationController alloc] initWithRootViewController:mVC] autorelease];
    [navi2.navigationBar setBackgroundImage:[UIImage imageNamed:@"999"] forBarMetrics:UIBarMetricsDefault];
    UINavigationController *navi3 = [[[UINavigationController alloc] initWithRootViewController:cVC] autorelease];
    [navi3.navigationBar setBackgroundImage:[UIImage imageNamed:@"999"] forBarMetrics:UIBarMetricsDefault];
    UINavigationController *navi4 = [[[UINavigationController alloc] initWithRootViewController:gVC] autorelease];
    [navi4.navigationBar setBackgroundImage:[UIImage imageNamed:@"999"] forBarMetrics:UIBarMetricsDefault];
    UINavigationController *navi5 = [[[UINavigationController alloc] initWithRootViewController:dVC] autorelease];
    [navi5.navigationBar setBackgroundImage:[UIImage imageNamed:@"999"] forBarMetrics:UIBarMetricsDefault];
    
    // 设置标签样式
    sVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"攻略" image:[UIImage imageNamed:@"1.png"] tag:1001] autorelease];
    mVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"搭配" image:[UIImage imageNamed:@"2.png"] tag:1002];
    cVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"案例" image:[UIImage imageNamed:@"3.png"] tag:1003];
    gVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"风水" image:[UIImage imageNamed:@"4.png"] tag:1004];
    dVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"日记" image:[UIImage imageNamed:@"5.png"] tag:1005];
    
    // 创建标签控制器
    self.tabBar = [[[UITabBarController alloc] init]autorelease];
    // 设置需要被标签控制器管理的控制器
    _tabBar.viewControllers = @[navi1, navi2, navi3, navi4, navi5];
    // 设置tabBar不透明
    _tabBar.tabBar.translucent = NO;
    // 设置代理人
    _tabBar.delegate = self;
   [self.tabBar.tabBar setBackgroundImage:[UIImage imageNamed:@"999999"]];
    self.LeftSlideVC = [[[LeftSlideViewController alloc] initWithLeftView:lVC andMainView:_tabBar] autorelease];
    // 把标签控制器设置为根视图控制器
    self.window.rootViewController = self.LeftSlideVC;
    [self created];
    [_window release];
    return YES;
    
}
// 禁用旋屏(在Xcode 4.5之后)

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{
    
    return (UIInterfaceOrientationMaskPortrait);
    
}
- (void)created
{
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(changeColor:) name:@"color" object:nil];
}
- (void)changeColor:(NSNotification *)noti
{
    NSString *str = [NSString stringWithFormat:@"%@%@", noti.object, noti.object];

    [self.tabBar.tabBar setBackgroundImage:[UIImage imageNamed:str]];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
